<template>
  <!-- 新增区 -->
  <div class="box">
    捐赠人：
    <input type="text" id="txtName" v-model.trim="pname" />
    受捐企业：
    <base-select id="selAddOrg" :lists="orgList" @selected="getOption">
      <template v-slot="option">
        {{ option.item.name }}
      </template>
    </base-select>
    金额：
    <input type="text" id="txtMoney" v-model.trim.number="money" />
    受捐日期：
    <input type="text" id="txtDate" v-model.trim="date" />
    <input type="button" id="btnAdd" value="新增" @click="handleClickAdd" />
  </div>
</template>

<script>
export default {
  props: {
    orgList: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      pname: "",
      money: "",
      date: "",
      selectOption: "",
    };
  },
  methods: {
    handleClickAdd() {
      if (!this.isCompleteData()) {
        alert("信息填写有误！");
        return;
      }
      const obj = {
        pname: this.pname,
        money: this.money,
        date: this.formatDate(this.date),
        orgId: this.selectOption,
      };

      //trigger add event and transfer new item to main component
      this.$emit("onclick", obj);
    },
  },
};
</script>

<style>
</style>